package com.angel.provider.health.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.angel.core.Constants;
import com.angel.core.base.BaseProviderImpl;
import com.angel.dao.health.BuzFamilyMapper;
import com.angel.health.BuzCustomer;
import com.angel.health.BuzDoctor;
import com.angel.health.BuzFamily;
import com.angel.provider.health.BuzFamilyProvider;

@Service
public class BuzFamilyProviderImpl extends BaseProviderImpl<BuzFamily> implements BuzFamilyProvider{
	
	@Autowired
	BuzFamilyMapper familyMapper;

	public int save(BuzFamily buzFamily) {
		Date date = new Date();
		buzFamily.setCreateTime(date);
		buzFamily.setUpdateTime(date);
		int i = familyMapper.insert(buzFamily);
		int idLen = buzFamily.getId().toString().length();
		String code = Constants.FAMILY_CODE;
		String _code = code.substring(0, code.length() - idLen)+buzFamily.getId();
		BuzFamily family = new BuzFamily();
		family.setId(buzFamily.getId());
		family.setCode(_code);
		familyMapper.updateByPrimaryKeySelective(family);
		return i;
	}

	@Override
	public List<BuzCustomer> queryCustomer(String search) {
		// TODO Auto-generated method stub
		return familyMapper.queryCustomer(search);
	}

	public BuzFamily getById(Integer id) {
		// TODO Auto-generated method stub
		return familyMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<BuzDoctor> queryDoctor(String search) {
		// TODO Auto-generated method stub
		return familyMapper.queryDoctor(search);
	}

}
